package com.hakim.wfb.web.controller.interest;

import com.hakim.wfb.admin.params.interest.*;
import com.hakim.wfb.admin.params.interest.GetConsumeInterestParam;
import com.hakim.wfb.admin.result.interest.ConsumeInterestView;
import com.hakim.wfb.admin.service.api.ConsumeInterestService;
import com.hkfs.fundamental.api.data.ListResultEx;
import com.hkfs.fundamental.api.data.ObjectResultEx;
import com.hkfs.fundamental.api.data.ResultEx;
import com.hkfs.fundamental.api.params.SessionIdentity;
import com.hkfs.fundamental.session.SessionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by walkman on 2017/7/18.
 */
@RestController
@RequestMapping(value = "/interest", name = "消费日息表")
public class ConsumeIntrestController {

    /**
     *
     */
    @Autowired
    private ConsumeInterestService consumeInterestService;

    /**
     * @param parameter
     * @return
     */
    @RequestMapping(value = "add", name = "日息添加", method = RequestMethod.POST)
    public ResultEx addInterest(AddConsumeInterestParam parameter, HttpServletRequest request) {
        SessionHandler handler = new SessionHandler();
        SessionIdentity identity = handler.getSessionIdentity(request, SessionIdentity.class);
        parameter.setSessionIdentity(identity);
        return consumeInterestService.addInterest(parameter);
    }

    /**
     * @param parameter
     * @return
     */
    @RequestMapping(value = "update", name = "日息编辑", method = RequestMethod.POST)
    public ResultEx updateInterest(UpdateConsumeInterestParam parameter, HttpServletRequest request) {
        SessionHandler handler = new SessionHandler();
        SessionIdentity identity = handler.getSessionIdentity(request, SessionIdentity.class);
        parameter.setSessionIdentity(identity);
        return consumeInterestService.updateInterest(parameter);
    }

    /**
     * @param parameter
     * @return
     */
    @RequestMapping(value = "delete", name = "日息修改", method = RequestMethod.POST)
    public ResultEx deleteInterest(DeleteConsumeInterestParam parameter, HttpServletRequest request) {
        SessionHandler handler = new SessionHandler();
        SessionIdentity identity = handler.getSessionIdentity(request, SessionIdentity.class);
        parameter.setSessionIdentity(identity);
        return consumeInterestService.deleteInterest(parameter);
    }

    /**
     * @param parameter
     * @return
     */
    @RequestMapping(value = "get", name = "日息查询", method = RequestMethod.POST)
    public ObjectResultEx<ConsumeInterestView> getInterest(GetConsumeInterestParam parameter, HttpServletRequest request) {
        SessionHandler handler = new SessionHandler();
        SessionIdentity identity = handler.getSessionIdentity(request, SessionIdentity.class);
        parameter.setSessionIdentity(identity);
        return consumeInterestService.getInterest(parameter);
    }

    /**
     * @param parameter
     * @return
     */
    @RequestMapping(value = "query", name = "日息查询", method = RequestMethod.POST)
    public ListResultEx<ConsumeInterestView> queryInterest(QueryConsumeInterestParamWebPage parameter, HttpServletRequest request) {
        SessionHandler handler = new SessionHandler();
        SessionIdentity identity = handler.getSessionIdentity(request, SessionIdentity.class);
        parameter.setSessionIdentity(identity);
        return consumeInterestService.queryInterest(parameter);
    }
}
